#默认值带出小于或等于2的值
resList = [0,1,1]
def flag(n):
    #递归到最后，因为flag(n-1) + flag(n-2)同时执行，n的值为1或2，直接return结果1
    if n == 1 or n == 2:
        return 1
    a = flag(n-1) + flag(n-2)
    #判断如果追加的值小于集合最后一个值时，则不添加值
    if(a > resList[-1]):
        resList.append(a)
    return a
n = 10
#因为resList集合有默认值，所以对于n小于2时，不执行函数 flag(),直接在外部处理
if n < 0:
    print("n不可以小与0")
elif n == 0:
    print("0")
elif n == 1:
    print("0,1")
else:
    flag(n)
    print(resList)








#树的遍历
class Solution:
    def levelOrder(self, root):
        """
        :type root: TreeNode
        :rtype: List[List[int]]
        """
        def helper(node, level):
            if not node:
                return
            else:
                sol[level-1].append(node.val)
                if len(sol) == level:  # 遍历到新层时，只有最左边的结点使得等式成立
                    sol.append([])
                helper(node.left, level+1)
                helper(node.right, level+1)
        sol = [[]]
        helper(root, 1)
        return sol[:-1]


# 循环实现

class Solutions:
    def levelOrder(self, root):
        if not root:
            return []
        sol = []
        curr = root
        queue = [curr]
        while queue:
            curr = queue.pop(0)
            sol.append(curr.val)
            if curr.left:
                queue.append(curr.left)
            if curr.right:
                queue.append(curr.right)
        return sol